package br.unicamp.ic.lsd;

import javax.jws.WebService;

import br.unicamp.ic.lsd.exceptions.DException;
import br.unicamp.ic.lsd.exceptions.GException;
import br.unicamp.ic.lsd.exceptions.JException;

@WebService(endpointInterface = "br.unicamp.ic.lsd.ServiceThree", serviceName = "webserviceThree")
public class ServiceThreeImpl implements ServiceThree {
    private static boolean DExceptionThrow = false;
    private static boolean GExceptionThrow = false;
    private static boolean JExceptionThrow = false;
    private static long timeoutMethodOne = 0;
    private static long timeoutMethodTwo = 0;
    private static long timeoutMethodThree = 0;

    @Override
    public String methodOneWSThree(int k) throws DException {
	if (DExceptionThrow)
	    k = 1;

	try {
	    Thread.sleep(timeoutMethodOne);
	} catch (InterruptedException e) {
	    e.printStackTrace();
	}

	switch (k) {
	case 0:
	    return "methodOneWSThree executado com sucesso";
	case 1:
	    throw new DException("Falha do metodo methodOneWSThree");
	}
	return "Algum erro ocorreu no metodo methodOneWSThree";
    }

    @Override
    public String methodTwoWSThree(int k) throws GException {
	if (GExceptionThrow)
	    k = 1;

	try {
	    Thread.sleep(timeoutMethodTwo);
	} catch (InterruptedException e) {
	    e.printStackTrace();
	}

	switch (k) {
	case 0:
	    return "methodTwoWSThree executado com sucesso";
	case 1:
	    throw new GException("Falha do metodo methodTwoWSThree");
	}
	return "Algum erro ocorreu no metodo methodTwoWSThree";
    }

    @Override
    public String methodThreeWSThree(int k) throws JException {
	if (JExceptionThrow)
	    k = 1;

	try {
	    Thread.sleep(timeoutMethodThree);
	} catch (InterruptedException e) {
	    e.printStackTrace();
	}

	switch (k) {
	case 0:
	    return "methodThreeWSThree executado com sucesso";
	case 1:
	    throw new JException("Falha do metodo methodThreeWSThree");
	}
	return "Algum erro ocorreu no metodo methodThreeWSThree";
    }

    @Override
    public boolean isDExceptionThrow() {
	return DExceptionThrow;
    }

    @Override
    public void setDExceptionThrow(boolean dExceptionThrow) {
	DExceptionThrow = dExceptionThrow;
    }

    @Override
    public boolean isGExceptionThrow() {
	return GExceptionThrow;
    }

    @Override
    public void setGExceptionThrow(boolean gExceptionThrow) {
	GExceptionThrow = gExceptionThrow;
    }

    @Override
    public boolean isJExceptionThrow() {
	return JExceptionThrow;
    }

    @Override
    public void setJExceptionThrow(boolean jExceptionThrow) {
	JExceptionThrow = jExceptionThrow;
    }

    @Override
    public long getTimeoutMethodOne() {
	return timeoutMethodOne;
    }

    @Override
    public void setTimeoutMethodOne(long timeoutMethodOne) {
	ServiceThreeImpl.timeoutMethodOne = timeoutMethodOne;
    }

    @Override
    public long getTimeoutMethodTwo() {
	return timeoutMethodTwo;
    }

    @Override
    public void setTimeoutMethodTwo(long timeoutMethodTwo) {
	ServiceThreeImpl.timeoutMethodTwo = timeoutMethodTwo;
    }

    @Override
    public long getTimeoutMethodThree() {
	return timeoutMethodThree;
    }

    @Override
    public void setTimeoutMethodThree(long timeoutMethodThree) {
	ServiceThreeImpl.timeoutMethodThree = timeoutMethodThree;
    }
}
